#ifndef XGE_XFILE_GENERAL_OPERATION_H_
#define XGE_XFILE_GENERAL_OPERATION_H_
#include "xge_common_config.h"
#include "xstring.h"
#include "xrt_error.h"
#include "xbase_common.h"

#include <Windows.h>
#include <iterator>

namespace xge{

  // XFileSearch class is a simple interface for iterating
  // the file and folder in a specific target path , using
  // Win32 file wildcard to generate result .
  class FileSearch {
  public:
    FileSearch  ( const char_t* wildcard ): find_handle_ ( INVALID_HANDLE_VALUE ) {
      Research(wildcard);
    }
    FileSearch  () : find_handle_ ( INVALID_HANDLE_VALUE ) {}
    ~FileSearch () ;
  public:
    void Research( const char_t* wildcard );
    // This next may omit the system file or other stuff
    // internally 
    void Next() ;
    bool HasNext() const {
      return find_handle_ != INVALID_HANDLE_VALUE;
    }
    bool is_file() const  {
      return 
        // not a archive in local windows system
        ( (find_data_.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == 0 ) &&
        // filtering the system file here
        ( (find_data_.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM ) == 0 );
    }
    bool is_directory() const{
      return static_cast<bool>( (find_data_.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) !=0 );
    }
    const char_t* file_name() const {
      return find_data_.cFileName;
    }
  private:
#ifdef XGE_USE_WIDE_CHAR
    ::WIN32_FIND_DATAW find_data_;
#else
    ::WIN32_FIND_DATAA find_data_;
#endif 
    ::HANDLE find_handle_;
    friend class FileSearch;
  };

  // Create a folder in the specific place
  // If the folder is existed it will return kFailed
  // If the API calling encounter a problem , it will
  // return kException
  // Otherwise , it will return kSucceed
  bool CreateFolder( const char_t* path );


}//namespace xge
#endif// XGE_XFILE_GENERAL_OPERATION_H_